/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package proyectoprogracuestionario;

import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JPasswordField;
import javax.swing.border.BevelBorder;

/**
 *
 * @author Paul
 */
public class VentPrincipal extends JFrame implements ActionListener {
    
     private VentAdministrador admi;
    private JButton ingreso, limpiar;
    private JPasswordField clave;
    private JComboBox seleccion;
    private JLabel usuario, lblcontraseña, lblinicio;
     private JPanel sur = new JPanel();
    private JPanel centro = new JPanel();
    private JPanel norte = new JPanel();
    private String Seleccion;
    
    public VentPrincipal(){
        //this.setLocationRelativeTo(null);
        this.setSize(600, 200);          
        this.setLayout(new BorderLayout());
       this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setTitle("CUESTIONARIOS");
       // this.setModal(true);
         admi=new VentAdministrador();
         norte.setLayout(new GridLayout(1,5,5,5));
        norte.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
         lblinicio=new JLabel("Ingrese el tipo de usuario y contraseña");
         norte.add(lblinicio);
         
        centro.setLayout(new GridLayout(2,5,5,5));
        centro.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        usuario=new JLabel("Tipo de Usuario");
        lblcontraseña=new JLabel("Contraseña");
        centro.add(usuario);
        seleccion = new JComboBox();
        seleccion.setBounds(10,10,80,20);
        add(seleccion);
        seleccion.addItem("Administrador");
        seleccion.addItem("Usuario");
        centro.add(seleccion);
        //seleccion.addItemListener(this);
        clave = new JPasswordField(4);
        clave.setBounds(10,10,80,20);
        this.getContentPane().add(clave);
       
        centro.add(lblcontraseña);
         
         
         centro.add(clave);
         
         sur.setLayout(new GridLayout(1,5,5,5));
        sur.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
        ingreso= new JButton("Ingreso");
         this.getContentPane().add(ingreso);
         limpiar = new JButton("Limpiar");
         this.getContentPane().add(limpiar);
         sur.add(ingreso);
         sur.add(limpiar);
        this.add(norte,BorderLayout.NORTH);
         this.add(centro,BorderLayout.CENTER);
         this.add(sur,BorderLayout.SOUTH);
         ingreso.addActionListener(this);
         limpiar.addActionListener(this);
    }
    
     public void actionPerformed(ActionEvent e) {
        if(e.getSource().equals(ingreso)){
             Seleccion=seleccion.getSelectedItem().toString();
            String ClaveAdministrador="246";
        String ClaveUser="369";
        String Obtener;
        Obtener=clave.getText();
        if (ClaveAdministrador == null ? Obtener == null : ClaveAdministrador.equals(Obtener)){
            if(Seleccion.equals("Administrador")){
                //this.
            admi.setVisible(true);
            //mainPanel.setVisible(false);
            
            
            }
            
        }
        
        else if (ClaveUser.equals(Obtener)&&(Seleccion.equals("Usuario"))){
            
            
  
                 
                //dlgUser.setVisible(true);
                //Usuario.setText("");
            
        
        }
        else{
                JOptionPane.showMessageDialog(null,"Contraseña o Usuario Invalido","Error",JOptionPane.ERROR_MESSAGE);
                clave.setText("");
            }
        try {
           this.finalize();
        } catch (Throwable ex) {
            Logger.getLogger(VentPrincipal.class.getName()).log(Level.SEVERE, null, ex);
        }
            
        }
        if(e.getSource().equals(limpiar)){
            clave.setText("");
        }
            
        }
     
    
}
